<template>
  <div class="h-full flex flex-col">
    <iframe id="preview-iframe" src="" width="100%" height="100%"></iframe>
  </div>
</template>

<script>
import axios from 'axios'
import jwt from 'jwt-simple'
import storage from "store";
import { ACCESS_TOKEN } from "@/store/mutation-types";
export default {
  data() {
    return {
    }
  },
  mounted() {
    const reportName = sessionStorage.getItem('report');
    // console.log('reportName',reportName);
    axios.get(process.env.VUE_APP_BASE_API + '/' + reportName, {
      responseType: 'arraybuffer',
      headers: {
        token: storage.get(ACCESS_TOKEN),
        tokens: storage.get("bmwToken") || "",
        YtAuth: jwt.encode({ bmw: 1 }, 'jwt'),
      },
    })
      .then((response) => {
        const iframe = document.getElementById('preview-iframe');
        const blob = new Blob([response.data], { type: 'application/pdf' });
        iframe.src = URL.createObjectURL(blob);
      })
      .catch((error) => {
        console.error('Error fetching file:', error);
      });
  },
}

</script>

<style lang="less" scoped></style>